package ATest;

import java.util.Arrays;

/**
 * ClassName: Test01
 * Package: ATest
 * Description:
 *
 * @Author BCXJ
 * @Create 2025/6/10 19:17
 * @Version 1.0
 * @Since 1.0
 */
public class Test01 {

    public static void main(String[] args) {
        int[] arr = {3,2,1};
        sort(arr);
        System.out.println(Arrays.toString(arr));
    }

    // 插入排序
    public static void sort(int[] arr) {
        for (int i = 1; i < arr.length; i++) {
            for (int j = i; j > 0 && arr[j] < arr[j - 1]; j --) {
                swap(arr, j, j - 1);
            }
        }
    }

    public static void swap(int[] arr, int i, int j) {
        if(i == j) {
            return;
        }
        arr[i] = arr[i] ^ arr[j];
        arr[j] = arr[i] ^ arr[j];
        arr[i] = arr[i] ^ arr[j];
    }
}
